<template>
  <div>
    <!-- 添加种类按钮 -->
    <input type="text" style="float: left; margin-top: 15px; margin-right: 15px;" placeholder="输入添加商品类别"
      v-model="typeName.typeName" />
    <div style="float: left;"> <el-button @click="addGoodType">添加商品类别</el-button>
    </div>

    <!--    //积分商城类别展示表格-->
    <template>
      <el-table :data="goodsType" border style="width: 100%">
        <el-table-column fixed prop="typeName" label="类型名" width="150">
        </el-table-column>
        <el-table-column prop="addTime" label="创建时间" width="120">
        </el-table-column>
        <el-table-column prop="updateTime" label="跟新时间" width="120">
        </el-table-column>
        <el-table-column prop="operator" label="操作人" width="120">
        </el-table-column>
        <el-table-column label="操作" width="200">
          <template slot-scope="scope">
            <el-button v-if="scope.row.typeState==0" @click="modifyGoodTypeState(scope.row.typeId,1)" type="text"
              size="small">下架</el-button>
            <el-button v-if="scope.row.typeState==1" @click="modifyGoodTypeState(scope.row.typeId,0)" type="text"
              size="small">上架</el-button>
            <el-button @click="modifyGoodTypeState(scope.row.typeId,2)" type="text" size="small">删除</el-button>

          </template>
        </el-table-column>
      </el-table>
    </template>

  </div>


</template>

<script>
  export default {
    data() {
      return {
        goodsType: [],
        type: {},
        typeName: {}
      }

    },
    methods: {


      findGoodType() { //查看所有上头种类

        this.$http.post("/mall/type/findGoodTypeAll")
          .then(resp => {
            this.goodsType = resp.data.data

          })
      },
      modifyGoodTypeState(obj, obj1) { //修改类别状态

        this.type.tyepId = obj
        this.type.state = obj1
        this.$http.post("/mall/type/modifyGoodTypeState.admin", this.type)
          .then(resp => {

            this.findGoodType()
            if (resp.data.code != 200) {
              alert(resp.data.message)
            }

          })
      },
      addGoodType() {
        this.$http.post("/mall/type/addGoodType.admin", this.typeName)
          .then(resp => {
            this.findGoodType()

            if (resp.data.code != 200) {
              alert(resp.data.message)
            }

          })

      }

    },
    created() {
      this.findGoodType()
    }
  }
</script>

<style>
</style>
